package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.constant.GlobalConstants;
import com.smart.common.core.domain.R;
import com.smart.common.core.page.PageQuery;
import com.smart.common.exception.ServiceException;
import com.smart.system.domain.vo.AreaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.Bucket;
import com.smart.system.service.IBucketService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 垃圾桶Controller
 * 
 * @author smart
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/bucket")
@Api(tags = "垃圾桶")
public class BucketController extends BaseController
{
    @Autowired
    private IBucketService bucketService;

    /**
     * 查询垃圾桶列表
     */
    @ApiOperation(value = "查询垃圾桶列表")
    //@PreAuthorize("@ss.hasPermi('system:bucket:list')")
    @GetMapping("/list")
    public R<IPage<Bucket>> list(String bucketName,Integer type, PageQuery pageQuery)
    {
        return R.ok(bucketService.selectBucketList(bucketName,type,pageQuery.toPage()));
    }

    /**
     * 获取垃圾桶详细信息
     */
    @ApiOperation(value = "获取垃圾桶详细信息")
    //@PreAuthorize("@ss.hasPermi('system:bucket:query')")
    @GetMapping(value = "/{id}")
    public R<Bucket> getInfo(@PathVariable("id") String id)
    {
        return R.ok(bucketService.selectBucketById(id));
    }

    /**
     * 新增垃圾桶
     */
    @ApiOperation(value = "新增垃圾桶")
    //@PreAuthorize("@ss.hasPermi('system:bucket:add')")
    @Log(title = "垃圾桶", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Integer> add(@RequestBody Bucket bucket)
    {
        return R.ok(bucketService.insertBucket(bucket));
    }

    /**
     * 修改垃圾桶
     */
    @ApiOperation(value = "修改垃圾桶")
    //@PreAuthorize("@ss.hasPermi('system:bucket:edit')")
    @Log(title = "垃圾桶", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Integer> edit(@RequestBody Bucket bucket)
    {
        return R.ok(bucketService.updateBucket(bucket));
    }

    /**
     * 删除垃圾桶
     */
    @ApiOperation(value = "删除垃圾桶")
    //@PreAuthorize("@ss.hasPermi('system:bucket:remove')")
    @Log(title = "垃圾桶", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable String[] ids)
    {
        return R.ok(bucketService.deleteBucketByIds(ids));
    }

    @ApiOperation(value = "停用/启用垃圾桶")
    //@PreAuthorize("@ss.hasPermi('system:bucket:edit')")
    @Log(title = "垃圾桶", businessType = BusinessType.UPDATE)
    @PutMapping("/stop/{id}")
    public R<Integer> stop(@PathVariable String id)
    {
    	Bucket bucket = bucketService.selectBucketById(id);
        if(bucket==null){
            throw new ServiceException("此编号不存在!");
        }
    	if(bucket.getStatus().equals(GlobalConstants.FAIL)){
            bucket.setStatus(GlobalConstants.SUCCESS);
        }else{
            bucket.setStatus(GlobalConstants.FAIL);
        }
    	return R.ok(bucketService.updateBucket(bucket));
    }

    @ApiOperation(value = "获取垃圾站视频地址")
    @GetMapping("/getVideoUrl/{id}")
    public R<List<String>> getVideoUrl(@PathVariable String id){
        List<String> list = bucketService.getVideoUrl(id);
        return R.ok(list);
    }
}
